package GUI;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JDialog;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import Simulateur.Statistique;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

public class FenetreStatistique extends JDialog implements MouseListener {
	/**
	 * 
	 */
	
	private static final int HAUTEUR_FENETRE  = 300;
	private static final int LARGUEUR_FENETRE = 400;
	
	private static final long serialVersionUID = 1L;
	private JTable table;
	public FenetreStatistique(List<Statistique> list) {
		
		this.setTitle("Statistiques");
		this.setAlwaysOnTop(true);
		this.setBackground(new Color(125,100,75));
		this.setSize(LARGUEUR_FENETRE , HAUTEUR_FENETRE);
		this.setLocationRelativeTo(null);
		this.setResizable(true);
		this.setDefaultCloseOperation(HIDE_ON_CLOSE);
		
		StatTableModel model = new StatTableModel();
		model.setStatistique(list);
		
		table = new JTable(model);
		
		setLayout(new BorderLayout());
		add(table.getTableHeader(), BorderLayout.NORTH);
		add(table, BorderLayout.CENTER);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}


class StatTableModel extends AbstractTableModel {
    /**
	 * 
	 */
	private static final long serialVersionUID = -7195965822418759391L;
	private String[] columnNames = {"Date",
            "Strat�gie",
            "Type attente",
            "DMT",
            "DTP"};
    private ArrayList<Statistique> _statistiques;

    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        return _statistiques.size();
    }

    public String getColumnName(int col) {
        return columnNames[col].toString();
    }

    public Object getValueAt(int row, int col) {
        
    	Statistique stat = _statistiques.get(row);
    	
    	switch(col) {
    	case 0:
    		return stat.getDateCreation();
    		
    	case 1:
    		return stat.getStrategie().getNom();
    	
    	case 2:
    		return stat.getStrategieAttente().getNom();
    		
    	case 3:
    		return stat.getDMT();
    		
    	case 4:
    		return stat.getDTP();
    		
    	}
    	return null;
    }

    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        return false;
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(Object value, int row, int col) {
        
    }

    public void setStatistique(List<Statistique> list) {
    	_statistiques = (ArrayList<Statistique>) list;
    }
}


